<template>
  <div class="panelContainer">
    <div class="panelGrid">
      <!-- 充电设备卡片 -->
      <div class="panelCard">
        <div class="cardContent">
          <div class="iconWrapper bg1">
            <img class="cardIcon" src="@/assets/imgs/iconCharge.png" alt="充电设备" />
          </div>
          <div class="dataContent">
            <div class="cardTitle">充电设备总数</div>
            <div class="cardValue">
              <span class="number">{{ formatNumber(chartData.equipmentCount) }}</span>
              <span class="unit">支</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 累计场站卡片 -->
      <div class="panelCard">
        <div class="cardContent">
          <div class="iconWrapper bg2">
            <img class="cardIcon" src="@/assets/imgs/iconStation.png" alt="场站" />
          </div>
          <div class="dataContent">
            <div class="cardTitle">累计场站数量</div>
            <div class="cardValue">
              <span class="number">{{ formatNumber(chartData.stationCount) }}</span>
              <span class="unit">座</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 累计收益卡片 -->
      <div class="panelCard">
        <div class="cardContent">
          <div class="iconWrapper bg3">
            <img class="cardIcon" src="@/assets/imgs/iconWallet.png" alt="收益" />
          </div>
          <div class="dataContent">
            <div class="cardTitle">累计收益金额</div>
            <div class="cardValue">
              <span class="number">{{ formatNumber(chartData.earning) }}</span>
              <span class="unit">元</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 实时报警卡片 -->
      <div class="panelCard">
        <div class="cardContent">
          <div class="iconWrapper bg4">
            <img class="cardIcon" src="@/assets/imgs/iconAlarm.png" alt="报警" />
          </div>
          <div class="dataContent">
            <div class="cardTitle">实时报警数量</div>
            <div class="cardValue">
              <span class="number">{{ formatNumber(chartData.warningCount || 0) }}</span>
              <span class="unit">个</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  chartData: {
    type: Object,
    default: () => ({})
  }
})

const formatNumber = (num) => {
  // return num?.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') || '0'
  return num
}
</script>

<style scoped>
.panelContainer {
  width: 100%;
  /* height: 120px; */
  /* margin-top: 20px; */
  box-sizing: border-box;
}

.panelGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 40px;
  height: 100%;
}

.panelCard {
  position: relative;
  background: rgba(13, 18, 23, 0.7);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  pointer-events: auto;
}

.panelCard:hover {
  transform: translateY(-4px);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
}

.panelCard::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.05) 50%, transparent 100%);
  transform: translateX(-100%);
  /* animation: lightMove 3s infinite; */
}

@keyframes lightMove {
  to {
    transform: translateX(100%);
  }
}

.cardContent {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 48px;
}

.iconWrapper {
  width: 104px;
  height: 104px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 32px;
  flex-shrink: 0;
}

.iconWrapper.bg1 {
  background: linear-gradient(135deg, #0062ff15, #0062ff30);
}
.iconWrapper.bg2 {
  background: linear-gradient(135deg, #00b87915, #00b87930);
}
.iconWrapper.bg3 {
  background: linear-gradient(135deg, #ffa60015, #ffa60030);
}
.iconWrapper.bg4 {
  background: linear-gradient(135deg, #ff424215, #ff424230);
}

.cardIcon {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.dataContent {
  flex: 1;
  min-width: 0;
}

.cardTitle {
  font-size: 28px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cardValue {
  display: flex;
  align-items: baseline;
}

.cardValue .number {
  font-size: 48px;
  font-weight: 500;
  color: #ffffff;
  font-family: 'DIN';
  margin-right: 8px;
}

.cardValue .unit {
  font-size: 28px;
  color: rgba(255, 255, 255, 0.6);
}
</style>
